#include<bits/stdc++.h>

using namespace std;

int main() {
    int n = 40585;//n=4!+0!+5!+8!+5!
    for (n = 1; n <= 1e7; n++) {

        int m = 0;
        int t = n;
        while (t > 0) {

            int d = t % 10;
            int s = 1;
            for (int i = 1; i <= d; i++) {
                s *= i;
            }
            m += s;
            t /= 10;
        }
        if (m == n)
            cout << m << endl;
    }

    return 0;
}
